home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue61 / Clinic / ActionTracerFormU.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2000-06-28  |  2.0 KB  |  79 lines

  1. unit ActionTracerFormU;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   AppEvnts, StdCtrls, Buttons;
  8.  
  9. type
  10.   TActionTracerForm = class(TForm)
  11.     AppEvents: TApplicationEvents;
  12.     chkOn: TCheckBox;
  13.     chkSkipHints: TCheckBox;
  14.     btnClearList: TSpeedButton;
  15.     lstActions: TListBox;
  16.     Label1: TLabel;
  17.     procedure btnClearListClick(Sender: TObject);
  18.     procedure AppEventsActionExecute(Action: TBasicAction;
  19.       var Handled: Boolean);
  20.     procedure AppEventsShortCut(var Msg: TWMKey; var Handled: Boolean);
  21.   end;
  22.  
  23. implementation
  24.  
  25. {$R *.DFM}
  26.  
  27. uses
  28.   StdActns;
  29.  
  30. //Form variable moved here so:
  31. // a) The form won't be auto-created - it will be entirely managed from here
  32. // b) No one else can mess with the form
  33. var
  34.   ActionTracerForm: TActionTracerForm;
  35.  
  36. procedure TActionTracerForm.btnClearListClick(Sender: TObject);
  37. begin
  38.   lstActions.Items.Clear
  39. end;
  40.  
  41. procedure TActionTracerForm.AppEventsActionExecute(Action: TBasicAction;
  42.   var Handled: Boolean);
  43. begin
  44.   //If we are tracing
  45.   if chkOn.Checked then
  46.   begin
  47.     //If not tracing hint actions, then ignore them
  48.     if (Action is THintAction) and chkSkipHints.Checked then
  49.       Exit;
  50.     //Format a nice string and add it to the list
  51.     lstActions.Items.Add(Format('%s: %s', [Action.Name, Action.ClassName]));
  52.     //Make last item selected, which forces it into view
  53.     lstActions.ItemIndex := lstActions.Items.Count - 1
  54.   end
  55. end;
  56.  
  57. procedure TActionTracerForm.AppEventsShortCut(var Msg: TWMKey;
  58.   var Handled: Boolean);
  59.  
  60.   function KeyDown(KeyCode: Integer): Boolean;
  61.   begin
  62.     Result := GetKeyState(KeyCode) and $8000 > 0
  63.   end;
  64.  
  65. begin
  66.   if (Msg.CharCode = Ord('Z')) and KeyDown(vk_Control) and
  67.      KeyDown(vk_Shift) and KeyDown(vk_Menu) then
  68.     Show
  69. end;
  70.  
  71. initialization
  72.   ActionTracerForm := TActionTracerForm.Create(nil);
  73.   if FindCmdLineSwitch('ActionTrace', ['-', '/'], True) then
  74.     ActionTracerForm.Show
  75. finalization
  76.   ActionTracerForm.Free;
  77.   ActionTracerForm := nil
  78. end.
  79.